home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games Extra 1996 September / Amiga Games Extra CD-ROM 9-1996.iso / userbox / publicdomain / wbstars / source / wbstars_plot.c < prev    next >
C/C++ Source or Header  |  1996-07-09  |  4KB  |  220 lines

  1. /* $VER: WBStars_plot.c 1.02 (09.07.1996) */
  2.  
  3. #include "WBStars_include.h"
  4. #include "WBStars_protos.h"
  5. #include "WBStars_gui.h"
  6.  
  7. #define    SCX(x)        ((short)(((0.5*(x)/SCB)+0.5)*((double)maxx)))
  8. #define    SCY(y)        ((short)(((0.5*(y)/SCB)+0.5)*((double)maxy)))
  9. #define    leng(s)        (sqrt(star[(s)].x3*star[(s)].x3+star[(s)].y3*star[(s)].y3+star[(s)].z3*star[(s)].z3))
  10. #define rndneg()    (2.0*((double)(rand()-INT_MAX/2))/(double)INT_MAX)
  11.  
  12. double    COCH[10]={0.3, 1.0, 10.0, 39.0, 102.0, 214.0, 392.0, 656.0 ,1024.0 ,1516.0};
  13. double    SLEN;
  14. double    maxd;
  15. double    dx;
  16. double    dy;
  17. double    dz;
  18.  
  19. void    NewStars()
  20. {
  21.     char    i;
  22.  
  23.     SLEN=sqrt(sqrt((double)warpf));
  24.     maxd=2.0*c*(COCH[warpf]+1.0)/sqrt((double)warpf+1.0);
  25.     dx=-0.04*c*COCH[warpf]*sin(((double)az)*PI/180.0);
  26.     dy=-0.04*c*COCH[warpf]*sin(((double)he)*PI/180.0);
  27.     dz=-0.04*c*COCH[warpf]*cos(((double)az)*PI/180.0)*cos(((double)he)*PI/180.0);
  28.     for(i=0; i<anzstars; i++)
  29.     {
  30.         NewStar(i);
  31.     }
  32. }
  33.  
  34. void    NewStar( char i )
  35. {
  36.     double    azimut;
  37.     double    height;
  38.     double    temp;
  39.  
  40.     azimut=rndneg()*PI;
  41.     height=rndneg()*PID2;
  42.     star[i].x3=maxd*sin(azimut);
  43.     star[i].y3=maxd*sin(height);
  44.     star[i].z3=maxd*cos(azimut)*cos(height);
  45.     if(star[i].z3<dz*SLEN+1.0)
  46.     {
  47.         if(dz>0.0)
  48.         {
  49.             temp=(dz*SLEN+1.0-star[i].z3)/dz;
  50.             star[i].z3=dz*SLEN+1.0;
  51.             star[i].x3=star[i].x3+dx*temp;
  52.             star[i].y3=star[i].y3+dy*temp;
  53.             if( leng(i)>maxd )
  54.             {
  55.                 NewStar(i);
  56.             }
  57.         }
  58.         else
  59.         {
  60.             NewStar(i);
  61.         }
  62.     }
  63.     star[i].anzpoints=0;
  64. }
  65.  
  66. void    ClearStar( char i )
  67. {
  68.     char    n;
  69.     BYTE    drmd;
  70.  
  71.     if(star[i].anzpoints>0)
  72.     {
  73.         for( n=0; n<star[i].anzpoints; n++)
  74.         {
  75.             if( (mode==MODE_WIN) || (ReadPixel(RastP,star[i].x[n],star[i].y[n])==star[i].col[n]) )
  76.             {
  77.                 drmd=RastP->DrawMode;
  78.                 if((drmd==JAM1)||(drmd==JAM2))
  79.                 {
  80.                     SetAPen(RastP,bgpen);
  81.                     WritePixel(RastP,star[i].x[n],star[i].y[n]);
  82.                 }
  83.                 else
  84.                 {
  85.                     Forbid();
  86.                     SetDrMd(RastP,JAM1);
  87.                     SetAPen(RastP,bgpen);
  88.                     WritePixel(RastP,star[i].x[n],star[i].y[n]);
  89.                     SetDrMd(RastP,drmd);
  90.                     Permit();
  91.                 }
  92.             }
  93.         }
  94.         star[i].anzpoints=0;
  95.     }
  96. }
  97.  
  98. void    PlotStar( char i )
  99. {
  100.     double    fx,fy,fx2,fy2,dz3;
  101.     short    x,y,dx2,dy2,e,c1,c2;
  102.     short    ix1=1,iy1=0;
  103.     short    ix2=0,iy2=1;
  104.     char    pix,n;
  105.     char    color;
  106.     BYTE    drmd;
  107.  
  108.     star[i].x3=star[i].x3+dx;
  109.     star[i].y3=star[i].y3+dy;
  110.     star[i].z3=star[i].z3+dz;
  111.     if( (leng(i)>=maxd) || (star[i].z3<1.0) || (star[i].z3<1.0+SLEN*dz) )
  112.     {
  113.         NewStar(i);
  114.     }
  115.     fx2=star[i].x3/star[i].z3;
  116.     fy2=star[i].y3/star[i].z3;
  117.     fx=(star[i].x3-dx*SLEN)/(star[i].z3-dz*SLEN);
  118.     fy=(star[i].y3-dy*SLEN)/(star[i].z3-dz*SLEN);
  119.     star[i].anzpoints=0;
  120.  
  121.     if( ((abs(fx2)<SCB)&&(abs(fy2)<SCB)) || ((abs(fx)<SCB)&&(abs(fy)<SCB)) )
  122.     {
  123.         if(warpf==0)
  124.         {
  125.             if(((abs(fx2)<SCB)&&(abs(fy2)<SCB))&&ReadPixel(RastP,SCX(fx2),SCY(fy2))==bgpen)
  126.             {
  127.                 star[i].anzpoints=1;
  128.                 star[i].x[0]=SCX(fx2);
  129.                 star[i].y[0]=SCY(fy2);
  130.                 star[i].col[0]=PEN[0]%anzcolors;
  131.                 Forbid();
  132.                 drmd=RastP->DrawMode;
  133.                 if((drmd==JAM1)||(drmd==JAM2))
  134.                 {
  135.                     SetAPen(RastP,PEN[0]%anzcolors);
  136.                     WritePixel(RastP,star[i].x[0],star[i].y[0]);
  137.                 }
  138.                 else
  139.                 {
  140.                     SetDrMd(RastP,JAM1);
  141.                     SetAPen(RastP,PEN[0]%anzcolors);
  142.                     WritePixel(RastP,star[i].x[0],star[i].y[0]);
  143.                     SetDrMd(RastP,drmd);
  144.                 }
  145.                 Permit();
  146.             }
  147.         }
  148.         else
  149.         {
  150.             dx2=SCX(fx2)-SCX(fx);
  151.             dy2=SCY(fy2)-SCY(fy);
  152.             if(dx2<0)ix1=-1;
  153.             if(dy2<0)iy2=-1;
  154.             dx2=abs(dx2);
  155.             dy2=abs(dy2);
  156.             if(dx2<dy2)
  157.             {        
  158.                 pix=dy2+1;
  159.                 ix2=ix1;
  160.                 ix1=0;
  161.                 iy1=iy2;
  162.                 iy2=0;
  163.                 c1=2*dx2;
  164.                 e=c1-dy2;
  165.                 c2=e-dy2;
  166.             }
  167.             else
  168.             {
  169.                 pix=dx2+1;
  170.                 c1=2*dy2;
  171.                 e=c1-dx2;
  172.                 c2=e-dx2;
  173.             }
  174.             x=SCX(fx2);
  175.             y=SCY(fy2);
  176.             dz3=dz*SLEN/((double)pix);
  177.  
  178.             pix=min(pix,MAXPOINTS)-2;
  179.             for(n=0; n<pix; n++)
  180.             {
  181.                 if((x>0)&&(x<maxx)&&(y>0)&&(y<maxy)&&(ReadPixel(RastP,x,y)==bgpen))
  182.                 {
  183.                     color=(unsigned char)abs(((double)npen)*(dz3*((double)n)/(dz*SLEN)));
  184.                     star[i].x[star[i].anzpoints]=x;
  185.                     star[i].y[star[i].anzpoints]=y;
  186.                     star[i].col[star[i].anzpoints]=PEN[color]%anzcolors;
  187.                     star[i].anzpoints++;
  188.                     Forbid();
  189.                     drmd=RastP->DrawMode;
  190.                     if((drmd==JAM1)||(drmd==JAM2))
  191.                     {
  192.                         SetAPen(RastP,PEN[color]%anzcolors);
  193.                         WritePixel(RastP,x,y);
  194.                     }
  195.                     else
  196.                     {
  197.                         SetDrMd(RastP,JAM1);
  198.                         SetAPen(RastP,PEN[color]%anzcolors);
  199.                         WritePixel(RastP,x,y);
  200.                         SetDrMd(RastP,drmd);
  201.                     }
  202.                     Permit();
  203.                 }
  204.                 x=x+ix1;
  205.                 y=y+iy1;
  206.                 if(e<0)
  207.                 {
  208.                     e=e+c1;
  209.                 }
  210.                 else
  211.                 {
  212.                     e=e+c2;
  213.                     x=x+ix2;
  214.                     y=y+iy2;
  215.                 }
  216.             }
  217.         }
  218.     }
  219. }
  220.